﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
using Weka;
using System.Reflection;

using System.Diagnostics;

namespace Test
{
    class Program
    {

        static void Main(string[] args)
        {
            var earthOrginalVersion1 = CreateEarthVersion1();
            var earthOrginalVersion2 = CreateEarthVersion2();
            var earthOrginalVersion3 = CreateEarthVersion3();

            var s = new Serliser();

            var version1Data = s.ToData(earthOrginalVersion1);
            var version2Data = s.ToData(earthOrginalVersion2);
            var version3Data = s.ToData(earthOrginalVersion3);

            var deserliserVersion1 = new Test.DeserliserVersion1();
            var deserliserVersion2 = new Test.DeserliserVersion2();
            var deserliserVersion3 = new Test.DeserliserVersion3();

            var earthVersion1FromVersion1Data = deserliserVersion1.FromData(version1Data);
            var earthVersion2FromVersion1Data = deserliserVersion2.FromData(version1Data);
            var earthVersion3FromVersion1Data = deserliserVersion3.FromData(version1Data);

            var earthVersion1FromVersion2Data = deserliserVersion1.FromData(version2Data);
            var earthVersion2FromVersion2Data = deserliserVersion2.FromData(version2Data);
            var earthVersion3FromVersion2Data = deserliserVersion3.FromData(version2Data);

            var earthVersion1FromVersion3Data = deserliserVersion1.FromData(version3Data);
            var earthVersion2FromVersion3Data = deserliserVersion2.FromData(version3Data);
            var earthVersion3FromVersion3Data = deserliserVersion3.FromData(version3Data);

            TestIsSame(earthOrginalVersion1, earthVersion1FromVersion1Data);
            TestIsSame(earthOrginalVersion1, earthVersion2FromVersion1Data);
            TestIsSame(earthOrginalVersion1, earthVersion3FromVersion1Data);

            TestIsSame(earthOrginalVersion2, earthVersion1FromVersion2Data);
            TestIsSame(earthOrginalVersion2, earthVersion2FromVersion2Data);
            TestIsSame(earthOrginalVersion2, earthVersion3FromVersion2Data);

            TestIsSame(earthOrginalVersion3, earthVersion1FromVersion3Data);
            TestIsSame(earthOrginalVersion3, earthVersion2FromVersion3Data);
            TestIsSame(earthOrginalVersion3, earthVersion3FromVersion3Data);

        }

        private static Version1.Earth CreateEarthVersion1()
        {
            var earthOrginalVersion1 = new Version1.Earth
            {
                Diameter = 12756320,
                Countries = new[] { 
                    new Version1.Country { Name = "Afghanistan", Population = 28150000 },
                    new Version1.Country { Name = "Bahamas", Population = 309156 },
                    new Version1.Country { Name = "Cambodia", Population = 14000000 },
                    new Version1.Country { Name = "Denmark",Population = 5534738, },
                    new Version1.Country { Name = "East Timor", Population = 1134000, },
                    new Version1.Country { Name = "Indonesia", Population = 229965000, },
                    new Version1.Country { Name = "New Zealand", Population = 4000000, },
                },
            };

            return earthOrginalVersion1;
        }


        private static Version2.Earth CreateEarthVersion2()
        {
            var earthOrginalVersion2 = new Version2.Earth
            {
                Diameter = 12756320,
                Countries = new[] { 
                    new Version2.Country { Name = "Afghanistan", Population = 28150000, PrimaryReligion = Version2.Religion.Islam, IsDemocracy = false, Notes = "Islamic Republic of Afghanistan جمهوری اسلامی افغانستان (Persian: Jomhūrī-ye Eslāmī-ye Afġānistān) د افغانستان اسلامي جمهوریت (Pashto: Da Afġānistān Islāmī Jomhoriyat). The name Afghānistān, Persian: افغانستان [avɣɒnestɒn],[12] means \"Land of Afghans\", from the word Afghan. The first part of the name, \"Afghan\", is an alternative name for the Pashtuns who are the founders and the largest ethnic group of the country. They probably began using the term Afghan as a name for themselves since at least the Islamic period and onwards. According to W. K. Frazier Tyler, M. C. Gillet and several other scholars \"the word Afghan first appears in history in the Ḥudūd al-ʿĀlam in 982 AD.\" Al-Biruni referred to Afghans as various tribes living on the western frontier mountains of the Indus River, which would be the Sulaiman Mountains. From a more limited, ethnological point of view, \"Afghān\" is the term by which the Persian-speakers of Afghanistan (and the non-Paštō-speaking ethnic groups generally) designate the Paštūn. The equation [of] Afghan [and] Paštūn has been propagated all the more, both in and beyond Afghanistan, because the Paštūn tribal confederation is by far the most important in the country, numerically and politically. The term \"Afghān\" has probably designated the Paštūn since ancient times. Under the form Avagānā, this ethnic group is first mentioned by the Indian astronomer Varāha Mihira in the beginning of the 6th century CE in his Brihat-samhita."},
                    new Version2.Country { Name = "Bahamas", Population = 309156, PrimaryReligion = Version2.Religion.Christianity, Notes=""},
                    new Version2.Country { Name = "Cambodia", Population = 14000000, PrimaryReligion = Version2.Religion.Buddhism, Notes="The Kingdom of Cambodia (pronounced /kæmˈboʊdiə/), formerly known as Kampuchea (/kæmpuːˈtʃiːə/, ព្រះរាជាណាចក្រកម្ពុជា Preăh Réachéa Nachâk Kâmpŭchea, derived from Sanskrit Kambujadesa (कम्बोजदेश))...." },
                    new Version2.Country { Name = "Denmark",Population = 5534738,PrimaryReligion = Version2.Religion.Christianity, IsDemocracy = true },
                    new Version2.Country { Name = "East Timor", Population = 1134000, PrimaryReligion = Version2.Religion.Christianity, IsDemocracy = true,  },
                    new Version2.Country { Name = "Indonesia", Population = 229965000, PrimaryReligion = Version2.Religion.Islam, Towns = new []{new Version2.Town{Name="Jakarta", Population = 8490000}}},
                    new Version2.Country {Name = "New Zealand", Population = 4000000, PrimaryReligion = Version2.Religion.Christianity, Towns = new []{new Version2.Town{ Name="Wellington"}, new Version2.Town{ Name="Nelson"}, new Version2.Town{ Name="Christchurch", Population=350000 }, }, IsDemocracy = true, },
                },


                Oceans = new[]{
                    new Version2.Ocean{ Name = "Arctic", Area = 14056000, },
                    new Version2.Ocean{ Name = "Atlantic", Area = 106400000, },
                    new Version2.Ocean{ Name = "Indian", Area = 73556000, },
                    new Version2.Ocean{ Name = "Pacific", Area = 169200000, },
                    new Version2.Ocean{ Name = "Southern", Area = 20327000, }
                }
            };

            return earthOrginalVersion2;
        }



        private static Version3.Earth CreateEarthVersion3()
        {
            var earthOrginalVersion3 = new Version3.Earth
            {
                Diameter = 12756320,
                Countries = new[] { 
                    new Version3.Country { Name = "Afghanistan", Population = 28150000, PrimaryReligion = Version3.Religion.Islam, IsDemocracy = false, Notes = "Islamic Republic of Afghanistan جمهوری اسلامی افغانستان (Persian: Jomhūrī-ye Eslāmī-ye Afġānistān) د افغانستان اسلامي جمهوریت (Pashto: Da Afġānistān Islāmī Jomhoriyat). The name Afghānistān, Persian: افغانستان [avɣɒnestɒn],[12] means \"Land of Afghans\", from the word Afghan. The first part of the name, \"Afghan\", is an alternative name for the Pashtuns who are the founders and the largest ethnic group of the country. They probably began using the term Afghan as a name for themselves since at least the Islamic period and onwards. According to W. K. Frazier Tyler, M. C. Gillet and several other scholars \"the word Afghan first appears in history in the Ḥudūd al-ʿĀlam in 982 AD.\" Al-Biruni referred to Afghans as various tribes living on the western frontier mountains of the Indus River, which would be the Sulaiman Mountains. From a more limited, ethnological point of view, \"Afghān\" is the term by which the Persian-speakers of Afghanistan (and the non-Paštō-speaking ethnic groups generally) designate the Paštūn. The equation [of] Afghan [and] Paštūn has been propagated all the more, both in and beyond Afghanistan, because the Paštūn tribal confederation is by far the most important in the country, numerically and politically. The term \"Afghān\" has probably designated the Paštūn since ancient times. Under the form Avagānā, this ethnic group is first mentioned by the Indian astronomer Varāha Mihira in the beginning of the 6th century CE in his Brihat-samhita.", NationalDay = new DateTime(1919, 8, 19)  },
                    new Version3.Country { Name = "Bahamas", Population = 309156, PrimaryReligion = Version3.Religion.Christianity, Notes="" , NationalDay = new DateTime(1973, 7, 10) },
                    new Version3.Country { Name = "Cambodia", Population = 14000000, PrimaryReligion = Version3.Religion.Buddhism, Notes="The Kingdom of Cambodia (pronounced /kæmˈboʊdiə/), formerly known as Kampuchea (/kæmpuːˈtʃiːə/, ព្រះរាជាណាចក្រកម្ពុជា Preăh Réachéa Nachâk Kâmpŭchea, derived from Sanskrit Kambujadesa (कम्बोजदेश))....", NationalDay = new DateTime(1953, 11, 9)  },
                    new Version3.Country { Name = "Denmark",Population = 5534738,PrimaryReligion = Version3.Religion.Christianity, IsDemocracy = true, NationalDay = new DateTime(1849, 6, 5) },
                    new Version3.Country { Name = "East Timor", Population = 1134000, PrimaryReligion = Version3.Religion.Christianity, IsDemocracy = true, NationalDay = new DateTime(2002, 5, 20)},
                    new Version3.Country { Name = "Indonesia", Population = 229965000, PrimaryReligion = Version3.Religion.Islam, NationalDay = new DateTime(1945, 8, 17),  Towns = new []{new Version3.Town{Name="Jakarta", Population = 8490000, Latitude=6.24523611111111111111111111111111m, Longitude=106.66899166666666666666666666666667M }}},
                    new Version3.Country {Name = "New Zealand", Population = 4000000, PrimaryReligion = Version3.Religion.Christianity, Towns = new []{new Version3.Town{ Name="Wellington", Latitude=41M, Longitude=174}, new Version3.Town{ Name="Nelson", Latitude=42.28M, Longitude = 173.29M}, new Version3.Town{ Name="Christchurch", Population=350000, Latitude=43.534525M, Longitude=172.6414139M }, }, IsDemocracy = true, NationalDay = new DateTime(1840, 2, 6), Capital=new Version3.Town{ Name="Wellington"}  },
                },

                Oceans = new[]{
                    new Version3.Ocean{ Name = "Arctic", Area = 14056000, MaxDeapth = 5450, IsPolar = true},
                    new Version3.Ocean{ Name = "Atlantic", Area = 106400000, MaxDeapth = 8605, IsPolar = false},
                    new Version3.Ocean{ Name = "Indian", Area = 73556000, MaxDeapth = 7258, IsPolar = false},
                    new Version3.Ocean{ Name = "Pacific", Area = 169200000, MaxDeapth = 10911, IsPolar = false},
                    new Version3.Ocean{ Name = "Southern", Area = 20327000, MaxDeapth = 7236, IsPolar = true}
                },
                DistanceFromSun = 149597892,
                UserName = "Fred",
            };

            return earthOrginalVersion3;
        }

        private static void TestIsSame(object value1, object value2)
        {
            bool isSame = Test.Comparer.Compare(value1, value2);
            if (!isSame) throw new Exception();
        }

    }
}
